package cn.wlinker.video.monitor.utils;

import cn.hutool.core.util.ObjectUtil;
import cn.wlinker.video.monitor.config.VideoConfig;
import cn.wlinker.video.monitor.domain.dto.PlayUrlDTO;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

/**
 * 有效期工具类，单位秒
 *
 * @author gxsjx
 * @version 1.0
 * @date 2022/11/8
 */
@Configuration
@Getter
public class VideoConfigUtils {

    @Getter
    private static VideoConfig videoConfig;

    @Autowired
    private void setVideoConfig(VideoConfig config) {
        videoConfig = config;
    }

    public static void initPlayUrlDTO(PlayUrlDTO playUrlDTO) {
        if (ObjectUtil.isEmpty(playUrlDTO.getExpireTime())) {
            playUrlDTO.setExpireTime(videoConfig.getExpireTime());
        }
        if (ObjectUtil.isEmpty(playUrlDTO.getProtocol())) {
            playUrlDTO.setProtocol(videoConfig.getProtocol());
        }
        if (ObjectUtil.isEmpty(playUrlDTO.getType())) {
            playUrlDTO.setType(videoConfig.getType());
        }
        if (ObjectUtil.isEmpty(playUrlDTO.getQuality())) {
            playUrlDTO.setQuality(videoConfig.getQuality());
        }
        if (ObjectUtil.isEmpty(playUrlDTO.getSupportH265())) {
            playUrlDTO.setSupportH265(videoConfig.getSupportH265());
        }
    }
}
